﻿// See https://aka.ms/new-console-template for more information
using BaseKnowledge;
using BaseKnowledge.DTO;
using System.Text.Json;
using System.Xml.Linq;

Console.WriteLine("Hello, World!");

#region 1.验证？.的表现
//BaseCustomer b = default;
//var a = new BaseCustomer
//{
//    Age = b?.Age ?? 20,
//    Name = "张三",
//    Sex = "男"
//};
//var age = a.Age + (b?.Age??0);

//Console.WriteLine("age:" + a.ToString());
#endregion

#region 2.通道的使用
//ChannelDemo channelDemo = new ChannelDemo();
//channelDemo.CreateUnBoundMessage();

// 多消费者消费
//channelDemo.ConsumeUnBoundMessage();
//channelDemo.ConsumeUnBoundMessage();
//channelDemo.ConsumeUnBoundMessage();

//channelDemo.CreateBoundMessage();

//channelDemo.ConsumeBoundMessage();
//channelDemo.ConsumeBoundMessage();
//channelDemo.ConsumeBoundMessage();


#endregion

#region 3.验证Text.json的使用
//var jsonStr = @"{""name"":""菜鸟教程"",""url"":""www.runoob.com"",""slogan"":""学的不仅是技术，更是梦想！"",""student"":[{""name"":""张三"",""age"":4},{""name"":""李四"",""age"":45}]}";

//var str = new List<string> { "url" };
//var value = JsonElementDemo.GetModelValueByParameters(str, jsonStr);
//Console.WriteLine("value="+ value);

#endregion

#region 4.验证空对象序列化的表现
//var jsonStr2 = "{\"comm\":{\"severId\":\"2000039\",\"prcscd\":\"CMP019\",\"errorCode\":\"00000\",\"errorMsg\":\"交易成功\",\"workdate\":\"20230505\",\"worktime\":\"100856\",\"serialno\":\"00040000005494\",\"channelSeq\":\"T200003920230505100855740\",\"random_num\":\"\",\"tranInfo\":\"\"},\"data\":{}}";
//var result = System.Text.Json.JsonSerializer.Deserialize<ResultModel>(jsonStr2);
//if (result.data == null || System.Text.Json.JsonSerializer.Serialize(result.data) =="{}")
//{
//    Console.WriteLine("我是空对象");
//}
//Console.WriteLine(result+ System.Text.Json.JsonSerializer.Serialize(result));
#endregion

#region 5.使用事件
Publisher publisher = new Publisher();
Subscriber subscriber = new Subscriber();
// 订阅发布者
subscriber.Subscribe(publisher);
// 发布者发布事件
publisher.RaiseEvent();
#endregion

Console.ReadKey();
